package cn.foolishbird.hamal.frame.util;

import org.apache.commons.lang3.StringUtils;

/**
 * @author Eric
 * @version 1.0
 * @date 2020-10-13
 */
public class DBStringUtils {


    public static String toHump(String underline) {
        if (StringUtils.isBlank(underline)) {
            return "";
        }
        StringBuilder tmp = new StringBuilder();
        char[] chars = underline.toCharArray();
        int index = 0;
        while (index < chars.length) {
            char c = chars[index];
            if ('_' == c) {
                while ('_' == c) {
                    index++;
                    if (index >= chars.length) {
                         break;
                    }
                    c = chars[index];
                }
                if (index < chars.length) {
                    tmp.append((char) (c - 32));
                }
            } else {
                tmp.append(c);
            }
            index++;
        }
        return tmp.toString();
    }

    public static String toUnderline(String hump) {
        if (StringUtils.isBlank(hump)) {
            return "";
        }
        StringBuilder tmp = new StringBuilder();
        char[] chars = hump.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            char c = chars[i];
            if (c >= 'A' && c <= 'Z') {
                c = (char) (c + 32);
                tmp.append("_");
            }
            tmp.append(c);
        }
        return tmp.toString();
    }
}
